package com.annchain.og_browser.util;

import java.math.BigDecimal;
import java.text.DecimalFormat;


public class ByteUtils {
    private static long KB = 1024;
    private static long MB = 1024*1024;
    private static long GB = 1024*1024*1024;

    public static String getNetFileSizeDescription(long size) {
        StringBuffer bytes = new StringBuffer();
        DecimalFormat format = new DecimalFormat("###.00");
        if (size >= GB) {
            double i = (size / (GB * 1.0));
            bytes.append(format.format(i)).append("GB");
        }
        else if (size >= MB) {
            double i = (size / (MB * 1.0));
            bytes.append(format.format(i)).append("MB");
        }
        else if (size >= KB) {
            double i = (size / (KB * 1.0));
            bytes.append(format.format(i)).append("KB");
        }
        else if (size < KB) {
            if (size <= 0) {
                bytes.append("0B");
            }
            else {
                bytes.append((int) size).append("B");
            }
        }
        return bytes.toString();
    }

}
